package com.five.monkey.enums;

import org.apache.commons.lang3.StringUtils;

/**
 * @author jim
 * @desc
 * @date 2021-08-15 14:00
 */
public enum FunctionTypeEnum {

    DEFAULT("", "默认类型,为了match方法不返回null"),

    COPY("copy", "复制操作"),

    CREATE("create", ""),

    QUERY("query", ""),

    UPDATE("update", ""),

    DELETE("delete", "");

    private String functionType;

    private String desc;

    FunctionTypeEnum(String functionType, String desc) {
        this.functionType = functionType;
        this.desc = desc;
    }

    public static FunctionTypeEnum match(String functionType) {
        FunctionTypeEnum result = FunctionTypeEnum.DEFAULT;
        if (StringUtils.isNotBlank(functionType)) {
            FunctionTypeEnum[] functionTypeEnums = FunctionTypeEnum.values();
            for (FunctionTypeEnum functionTypeEnum : functionTypeEnums) {
                if (StringUtils.equalsIgnoreCase(functionTypeEnum.functionType, functionType)) {
                    result = functionTypeEnum;
                    break;
                }
            }
        }
        return result;
    }
}
